[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 putc()                  Write a Character to Stream (Macro)

 #include   <stdio.h>

 int putc(c,stream);                     The character written
 int        c;                           Character to be written
 FILE       *stream;                     Pointer to the file stream

    putc() writes a single character, 'c', to the output 'stream' at the
    current position.

       Returns:     The character written, if successful.  On error,
                    returns the value of EOF.  EOF is a legitimate
                    integer value, so use ferror() to detect errors on
                    the given 'stream'.

         Notes:     putc() performs the same operation as fputc(), but
                    putc() is a macro, while fputc() is a function.

   -------------------------------- Example ---------------------------------

    This example writes the letters of the alphabet to a file, checks for
    a write error, then closes the file.

           #include <stdio.h>

           FILE *in;
           int x;

           main()
           {
               if ((in = fopen("alph.dat","w+")) != NULL) {
                    for (x = 65; x < 91; x++) {
                         putc(x,in);
                         if(ferror(in))
                         printf("write error");
                    }
                    fclose(in);
               }
           }


See Also: fputc() getc() getchar()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson